<?php
class balancelr
{
public static function _curl($url ) {  
	$ch = curl_init();
	
	curl_setopt($ch, CURLOPT_URL, $url); 
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);  
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/6.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3"); 
	
	curl_setopt($ch,CURLOPT_TIMEOUT,200); 
	
	
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
	$result=curl_exec ($ch); 
	curl_close ($ch); 
	return $result; 
}

public static function getStrLR($string,$start,$end){
	$str = explode($start,$string);
	$str = explode($end,$str[1]);
	return $str[0];
}

public static function getLRBalance(){
	
	$year=gmdate("Y");
	$month=gmdate("m");
	$day=gmdate("d");
	
	$hour=gmdate("H");
	$data=":".$year.$month.$day.":".$hour;
	
	$hash=hash("SHA256",$data);
	
	$xml='<BalanceRequest id="123456">
	  <Auth> 
		<ApiName></ApiName>
		<Token>'.$hash.'</Token>
	  </Auth>
	
	  <Balance> 
	  <CurrencyId>LRUSD</CurrencyId>
	  <AccountId>U6593813</AccountId>
	  </Balance>
	  </BalanceRequest>'  ;
	  
	
	$url="https://api.libertyreserve.com/xml/balance.aspx?req=".urlencode($xml);
	$s=self::_curl($url);
	$balance=self::getStrLR($s,"<Value>","</Value>");
	
	return $balance;



}


}
?>
